﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.Model;
using HNQXYJ.BLL;

namespace HNQXYJ.HN_History
{
    public partial class HistoryMgr : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             HistoryDataBind( 1);
        }

        //前一页
        protected void PrePage_Click(object sender, EventArgs e)
        {
            int currPage = Convert.ToInt32(this.LbPageNumber.Text);
            currPage--;
            if (currPage < 1)
            {
                currPage = 1;
            }

            this.LbPageNumber.Text = currPage.ToString();
            this.txtPageNumber.Text = currPage.ToString();
            this.HistoryDataBind(currPage);

        }

        //后一页
        protected void NextPage_Click(object sender, EventArgs e)
        {
            int currPage = Convert.ToInt32(this.LbPageNumber.Text);
            currPage++;
            if (currPage > Convert.ToInt32(this.LbPageCount.Text))
            {
                currPage = Convert.ToInt32(this.LbPageCount.Text);
            }
           
            
            this.btnNextPage.Enabled = true;
            this.LbPageNumber.Text = currPage.ToString();
            this.txtPageNumber.Text = currPage.ToString();
            this.HistoryDataBind(currPage);
        }

        //跳转页
        protected void BtnGo_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int pageCount = Convert.ToInt32(this.LbPageCount.Text);
                int pageIndex = Convert.ToInt32(this.txtPageNumber.Text.Trim());
                if (pageIndex > pageCount)
                {
                    pageIndex = pageCount;


                }
                if (pageIndex < 1)
                {
                    pageIndex = 1;
                }
                this.LbPageNumber.Text = pageIndex.ToString();
                this.txtPageNumber.Text = pageIndex.ToString();
                this.HistoryDataBind(pageIndex);
            }
        }
        //数据绑定
        private void HistoryDataBind(int pageIndex)
        {
            int rowCount = 0;
            int pageCount = 0;
            string ranklevel = Session["ranklevel"].ToString() + "%";
            List<HistoryInfor> list = new HistoryInforBLL().GetDataPagedRankLevel(pageIndex, 20, ranklevel, out rowCount, out pageCount);
            if (list != null)
            {
              
             
                this.RpList.DataSource = list;
                this.RpList.DataBind();
                this.LbPageCount.Text = pageCount.ToString();
            }
               
        }
    }
}